# -*- coding:utf-8 -*-
from application import app, db
from flask import Blueprint, request, jsonify, make_response, g, redirect
from common.libs.Helper import ops_render
from common.libs.admin.UserService import UserService
from common.models.admin.erp_menu import ErpMenu

route_role = Blueprint('role_page', __name__)


@route_role.route("/list.go", methods=["GET", "POST"])
def roleList():
    if request.method == "GET":
        resp_data = {}
        req = request.args
        uid = req['uid'] if 'uid' in req else ''
        if not UserService.checkRoleMenu(g.current_role.id, uid):
            return ops_render("/admin/exception/404.html")

        menu = ErpMenu.query.filter_by(id=uid).first()

        resp_data['menu'] = menu

        return ops_render("/admin/role/role.html", resp_data)
